// CSE571 - game-manager.h
// Authors: Jonathan Wald, Daniel Sarfati, Guangle Fan
// This class manages all the different connections that a client-side player
// may have.           

#ifndef GAME_MANAGER_H
#define GAME_MANAGER_H

#include <vector>
#include <string>
#include <iostream>
#include <fstream>

#include "ace/SOCK_Stream.h"
#include "ace/Connector.h"
#include "ace/SOCK_Connector.h"
#include "ace/Service_Object.h"
#include "ace/Synch.h"

#include "msg-flag.h"
#include "client-interpreter.h"
#include "player-svc-handler.h"

typedef ACE_Connector<PlayerSvcHandler,ACE_SOCK_CONNECTOR>
    PlayerConnector;

class PlayerGame;

using namespace std;

class GameManager : ACE_Service_Object {

 public:
   GameManager();
   ~GameManager();
   static GameManager* instance(); 
   void connect_all();
   int parse_file(const char * filename);
   
   string get_name() { return name; }
   void set_name(string name) { this->name = name; }
   PlayerGame* get_game(int i) { return games[i]; }
   void game_quit (PlayerGame * game);
   unsigned int num_games() { return games.size(); }
   vector<PlayerGame*> games;
   void score_sended () { ++num_of_scores_sended; }
   void set_auto_act () { auto_act = true; }
   bool all_scores_sended () { return auto_act && ( MsgFlag::getNum() == (unsigned) num_of_scores_sended );  }
   ClientInterpreter interpreter;
   PlayerConnector* connector;
   ACE_Thread_Mutex games_lock;

   // Service methods
   virtual int init (int argc, char *argv[]);
   virtual int fini (void);
   virtual int suspend (void);
   virtual int resume (void);
   virtual int info (char **, size_t = 0);

   bool plays_holdem;
   bool plays_stud;
   bool plays_draw;
   bool auto_act;


 private:
   string name;
   int num_of_scores_sended;
   static GameManager* instance_;
   
};

#endif
